﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Linq;
using System.Xml.Linq;

namespace RFW.Silverlight.Weather
{
	public class Rain
	{
		public string HourDescription { get; set; }
		public double HourIN { get; set; }
		public double HourMetric { get; set; }
		public string TodayDescription { get; set; }
		public double TodayIN { get; set; }
		public double TodayMetric { get; set; }

		public override string ToString()
		{
			return this.HourDescription;
		}

		internal void Process(XDocument doc)
		{
			var data = from o in doc.Descendants("current_observation")
					   select new Rain
					   {
						   HourDescription = o.Element("precip_1hr_string").Value,
						   HourIN = Convert.ToDouble(o.Element("precip_1hr_in").Value),
						   HourMetric = Convert.ToDouble(o.Element("precip_1hr_metric").Value),
						   TodayDescription = o.Element("precip_today_string").Value,
						   TodayIN = Convert.ToDouble(o.Element("precip_today_in").Value),
						   TodayMetric = Convert.ToDouble(o.Element("precip_today_metric").Value)
					   };

			foreach (Rain o in data)
			{
				this.HourDescription = o.HourDescription;
				this.HourIN = o.HourIN;
				this.HourMetric = o.HourMetric;
				this.TodayDescription = o.TodayDescription;
				this.TodayIN = o.TodayIN;
				this.TodayMetric = o.TodayMetric;
			}
		}
	}
}
